package com.soladhoc.annonces.client.view.ui;

import com.google.gwt.cell.client.AbstractSafeHtmlCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.text.shared.SafeHtmlRenderer;
import com.soladhoc.annonces.server.domain.Annonce;
import com.soladhoc.annonces.shared.proxy.AnnonceProxy;

public class AnnonceCell extends AbstractSafeHtmlCell<AnnonceProxy>
{
    private final AnnonceCellTable annoncesTable;


    public AnnonceCell(AnnonceCellTable annoncesTable, SafeHtmlRenderer<AnnonceProxy> renderer)
    {
        super(renderer, "click");
        this.annoncesTable = annoncesTable;
    }


    @Override
    public void onBrowserEvent(Cell.Context context, Element parent, AnnonceProxy value, NativeEvent event,
            ValueUpdater<AnnonceProxy> valueUpdater)
    {
        super.onBrowserEvent(context, parent, value, event, valueUpdater);
        if ("click".equals(event.getType()))
        {
            annoncesTable.onDetail(value);
        }
    }


    @Override
    protected void render(Cell.Context context, SafeHtml data, SafeHtmlBuilder sb)
    {
        if (data != null)
        {
            sb.append(data);
        }
    }
}
